﻿<UserControl x:Class="ViewDataStructure"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:OMANE.Modules.Dashboarding" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal" Margin="5">
            <TextBlock Text="Zoom"  Margin="5" VerticalAlignment="Center"/>
            <Slider Focusable="False" Width="200" Minimum="-1" SmallChange="0.1" LargeChange="0.25" Maximum="1" Value="{Binding LogZoom, Mode=TwoWay,FallbackValue=0}" Name="ZoomSlider"/>
            <Button IsEnabled="False" Content="Creer une relation" Click="Button_Click_1" VerticalAlignment="Center" />
        </StackPanel>
        <ListBox Grid.Row="1" ItemsSource="{Binding DataSet.Tables}" >
           
            
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem" >
                    <Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
                    <Setter Property="Canvas.Left" Value="{Binding Mode=OneTime, Path=ExtendedProperties[CanvasLeft]}" />
                    <Setter Property="Canvas.Top" Value="{Binding Mode=OneTime, Path=ExtendedProperties[CanvasTop]}" />

                    <Setter Property="RenderTransform">
                        <Setter.Value>
                            <ScaleTransform 
                                ScaleX="{Binding RelativeSource={RelativeSource AncestorType=local:ViewDataStructure},  Path=DataContext.Zoom, FallbackValue=1}" 
                                ScaleY="{Binding RelativeSource={RelativeSource AncestorType=local:ViewDataStructure},  Path=DataContext.Zoom, FallbackValue=1}" /> 
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Template" >
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>


                                    <Thumb DockPanel.Dock="Top" DataContext="{Binding}" DragDelta="ThumbDragDelta">
                                            <Thumb.Template>
                                                <ControlTemplate TargetType="Thumb">
                                                    <Border Background="Violet">
                                                    <TextBlock Foreground="White"  HorizontalAlignment="Center" Text="{Binding TableName}"  Margin="5" />
                                                    </Border>
                                                </ControlTemplate>
                                            </Thumb.Template>
                                        </Thumb>
                                    <!--<TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" Text="{Binding DataSourceName}" />-->

                                    <DataGrid IsReadOnly="True" Grid.Row="1" ItemsSource="{Binding Columns}"  AutoGenerateColumns="False" BorderBrush="Violet">
                                        <DataGrid.Columns>
                                            <DataGridTemplateColumn SortMemberPath="DataType.Name" Width="20" >
                                                <DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Image Name="Image" Width="16" Height="16" Margin="1" VerticalAlignment="Center" HorizontalAlignment="Center"  />
                                                        
                                                        <DataTemplate.Triggers>
                                                            <DataTrigger Binding="{Binding DataType.Name}" Value="String" >
                                                                <Setter TargetName="Image" Property="Source" Value="{x:Static local:StandardIconImageSources.VARCAR16}" />
                                                            </DataTrigger>

                                                            <DataTrigger Binding="{Binding DataType.Name}" Value="Double" >
                                                                <Setter TargetName="Image" Property="Source" Value="{x:Static local:StandardIconImageSources.VARNUM16}" />
                                                            </DataTrigger>

                                                            <DataTrigger Binding="{Binding DataType.Name}" Value="DateTime" >
                                                                <Setter TargetName="Image" Property="Source" Value="{x:Static local:StandardIconImageSources.VARDATE16}" />
                                                            </DataTrigger>
                                                        </DataTemplate.Triggers>                                                       
                                                        
                                                    </DataTemplate>
                                                </DataGridTemplateColumn.CellTemplate>
                                            </DataGridTemplateColumn>
                                            <DataGridTextColumn  Binding="{Binding ColumnName}" Width="SizeToCells"/>
                                            
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Grid>

                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
            
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</UserControl>
